<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/list.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <style>
        .nav {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 50px;
        }

        .container {
            padding-top: 80px;
            height: auto;
        }

        .container-right {
            width: auto;
        }

        .blog-pagnation-wrapper {
            height: 40px;
            margin: 16px 0;
            text-align: center;
        }

        .blog-pagnation-item {
            display: inline-block;
            padding: 8px;
            border: 1px solid #d0d0d5;
            color: #333;
        }

        .blog-pagnation-item:hover {
            background: #4e4eeb;
            color: #fff;
        }

        .blog-pagnation-item.actvie {
            background: #4e4eeb;
            color: #fff;
        }

        .slideshow-container {
            width: 60%;
            margin: 50px auto;
            margin-bottom: 0px;
            position: relative;
            overflow: hidden;
        }

        .mySlides img {
            width: 100%;
            height: auto;
            display: block;
            margin: 0 auto;
        }

        .prev, .next {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            padding: 16px;
            color: white;
            font-weight: bold;
            font-size: 20px;
            transition: 0.6s ease;
            border-radius: 0 3px 3px 0;
            user-select: none;
            background-color: rgba(0, 0, 0, 0.8);
        }

        .next {
            right: 0;
            border-radius: 3px 0 0 3px;
        }
    </style>
    <link rel="stylesheet" href="editor.md/css/editormd.min.css"/>
    <script src="js/jquery.min.js"></script>
    <script src="js/common.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
</head>

<body>
<!-- 导航栏 -->
<div class="nav">
    <img src="img/logo2.jpg" alt="">
    <span class="title">博客系统</span>
    <!-- 用来占据中间位置 -->
    <span class="spacer"></span>
    <a href="blog_list.html">主页</a>
    <a href="myblog_list.html">我的博客</a>
    <a href="blog_add.html">写博客</a>
    <a href="login.html">登陆</a>
    <!--    <a href="javascript:logout()">注销</a>-->
    <a href="about.html">站长简介</a>
</div>
<!-- 在容器内添加轮播图 -->
<div class="slideshow-container">
    <div class="mySlides fade">
        <img src="img/web.jpg" style="width:70%; height:300px;">
    </div>

    <div class="mySlides fade">
        <img src="img/spring.jpg" style="width:70%; height:300px;">
    </div>

    <div class="mySlides fade">
        <img src="img/java.jpg" style="width:70%; height:300px;">
    </div>
    <div class="mySlides fade">
        <img src="img/linux.jpg" style="width:70%; height:300px;">
    </div>

    <!-- 左右箭头 -->
    <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
    <a class="next" onclick="plusSlides(1)">&#10095;</a>
</div>


<!-- 版心 -->
<div class="container">
    <!-- 右侧内容详情 -->
    <div class="container-right" style="width: 100%;">
        <!-- 每一篇博客包含标题, 摘要, 时间 -->
        <div id="artListDiv">
        </div>

        <hr>
        <div class="blog-pagnation-wrapper">
            <button class="blog-pagnation-item" onclick="goFirstPage()">首页</button>
            <button class="blog-pagnation-item" onclick="goBeforePage()">上一页</button>
            <button class="blog-pagnation-item" onclick="goNextPage()">下一页</button>
            <button class="blog-pagnation-item" onclick="goLastPage()">末页</button>
        </div>
    </div>
</div>
<script>
    let slideIndex = 1;

    function showSlides(n) {
        let i;
        let slides = document.getElementsByClassName("mySlides");
        if (n > slides.length) {
            slideIndex = 1;
        }
        if (n < 1) {
            slideIndex = slides.length;
        }
        for (i = 0; i < slides.length; i++) {
            slides[i].style.display = "none";
        }
        slides[slideIndex - 1].style.display = "block";
    }

    function plusSlides(n) {
        showSlides(slideIndex += n);
    }

    showSlides(slideIndex);


    var pindex = 1;
    var psize = 4;
    var pcount = 1;
    //得到当前 url 中的页码
    pindex = (getUrlValue("pindex") == "" ? 1 : getUrlValue("pindex"));

    function initPage() {
        jQuery.ajax({
            url: "/article/listbypage",
            type: "POST",
            data: {"pindex": pindex, "psize": psize},
            success: function (result) {
                console.log(result.data.list)
                if (result != null && result.code == 200 && result.data.list.length > 0) {
                    var artListHtml = "";
                    for (var i = 0; i < result.data.list.length; i++) {
                        var articleinfo = result.data.list[i];
                        artListHtml += '<div class="blog">';
                        artListHtml += '<div class="title">' + articleinfo.title + '</div>';
                        artListHtml += '<div class="date"><span>更新时间:</span>' + articleinfo.updatetime + '&nbsp;&nbsp;<span>阅读量:</span>' + articleinfo.rcount + '</div>';
                        artListHtml += '<div class="desc">' + articleinfo.content + '</div>';
                        artListHtml += '<a href="blog_content.html?id=' + articleinfo.id
                            + '" class="detail">查看 &gt;&gt;</a>';
                        artListHtml += '</div>';
                    }
                    jQuery("#artListDiv").html(artListHtml);
                    pcount = result.data.pcount;
                }
            }
        });
    }

    initPage();


    function goFirstPage() {
        if (pindex <= 1) {
            alert("当前已经在首页了");
            return;
        }
        location.href = "blog_list.html";
    }

    // 点击上一页按钮
    function goBeforePage() {
        if (pindex <= 1) {
            alert("当前已经在首页了");
            return;
        }
        pindex = parseInt(pindex) - 1;
        location.href = "blog_list.html?pindex=" + pindex;
    }

    function goNextPage() {
        if (pindex >= pcount) {
            alert("已经在末页了");
            return;
        }
        pindex = parseInt(pindex) + 1;
        location.href = "blog_list.html?pindex=" + pindex;
    }

    function goLastPage() {
        if (pindex >= pcount) {
            alert("已经在末页了");
            return;
        }
        location.href = "blog_list.html?pindex=" + pcount;
    }
</script>
</body>
</html>